package cn.pugle.base.thread.ticketlock;

import java.util.concurrent.ConcurrentHashMap;

/**
 * 没有同步问题, 不回收lock会memory leak一些object
 *
 * @author tzp
 * @since 2018/7/9
 */
public class TicketLock1 implements TicketLock {
    private static ConcurrentHashMap<Long, Object> locks = new ConcurrentHashMap<>();

    @Override
    public Object getLock(Long ticketNumber) {
        locks.putIfAbsent(ticketNumber, new Object());
        return locks.get(ticketNumber);
    }

    @Override
    public void removeLock(Long ticketNumber) {

    }
}
